package com.czk.durant.springframework.beans.factory.support;

import com.czk.durant.springframework.beans.factory.config.SingletonBeanRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/9 14:48
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {
    /**
     * 单例池
     */
    private Map<String, Object> singletonObjects = new HashMap<>(16);

    /**
     * 拿到单例对象
     *
     * @param beanName
     * @return
     */
    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }

    /**
     * 添加进单例池
     *
     * @param beanName
     * @param bean
     */
    protected void addSingleton(String beanName, Object bean) {
        singletonObjects.put(beanName, bean);
    }
}
